#include <string.h>
#include <array>
#include <iostream>
#include <string>
#include <sstream>
#include <clocale>
#include <list>
#include <fstream>
#include <vector>
#include <clocale>
#include "hr_time.h"
#include <Windows.h>
#include <queue>
#include <map>
#include "unordered_map_ip.h"
#include "data.h"
# pragma once

using namespace std;
namespace u31
{

	int RFac(int n)
	{
		if (n == 0)
		{
			return 1;
		}
		else
		{
			return n*RFac(n - 1);
		}
	}



	int IFac(int n)
	{
		int sum = 1;
		for (int i = 1; i < n; i++){
			sum = sum*(i + 1);

		}

		return sum;
	}


	double aSum(int n, int x){
		double sum = 0;
		for (int i = 0; i <= n; i++){
			sum = sum + ((-x)^(2*i) / RFac(2*i));

		}
		return sum;

	}

	double bSum(int n, int x){
		double sum = 0;
		for (int i = 0; i <= n; i++){
			sum = sum + ((-x) ^ (2 * i) / IFac(2*i));

		}
		return sum;

	}


	void mainone(){

		SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
		SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);

		CStopWatch w;

		cout << "UPPG 3.1 a" << endl;

		cout << "Test om a och b ger samma svar :" << endl;
		cout << RFac(4) << "=" << IFac(4) << endl;
		cout << endl;
		cout << "Exekveringstid algoritm a (rekursiv):" << endl;
		w.startTimer();
		cout << aSum(2, 4) << endl;
		w.stopTimer();
		cout << "Time =" << w.getElapsedTime() * 1000 << "ms" << endl;
		cout << endl;
		cout << "Exekveringstid algoritm b (iterativ):" << endl;
		w.startTimer();
		cout << bSum(2, 4) << endl;
		w.stopTimer();
		cout << "Time =" << w.getElapsedTime() * 1000 << "ms" << endl;




		system("pause");
	}

}




namespace u32{

	void maintwo(){

		SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
		SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);

		CStopWatch w;

		cout << "uppg 3.2" << endl;

		unordered_map_ip a;

		a.ReadFromFile("C:/Users/Jonas/Desktop/ip_two.txt");

		cout <<"antal unika ip: "<< a.TellSize() << endl;

		w.startTimer();
		cout <<"Antal uppkoplingar till ett ip som finns = "<< a.Antal("129.151.102.150") << endl;
		w.stopTimer();
		cout << "SearchTime =" << w.getElapsedTime() * 1000 << "ms" << endl;
		w.startTimer();
		cout << "Antal uppkopplingar till ett ip inte som finns =  " <<a.Antal("200.151.102.150") << endl;
		w.stopTimer();
		cout << "SearchTime =" << w.getElapsedTime() * 1000 << "ms" << endl;


		



		system("pause");
	}





} 

namespace u33{

	void mainthree(){

		cout << "uppg 3.3" << endl;

		u32::unordered_map_ip a;

		a.ReadFromFile("C:/Users/Jonas/Desktop/ip_two.txt");

		std::priority_queue<data> pq;


		for (auto x : a.v) {

			pq.push(data(x.first, x.second));

		}

		cout << "Lista med de mest frekvent uppkopplade ip-numren:" << endl;

		for (int i = 1; i < 11; i++)
		{
			std::cout << pq.top() << endl;
			pq.pop();
		}

		std::cout << '\n';





		system("pause");
	}
}

	int main(){
		u31::mainone();
		u32::maintwo();
		u33::mainthree();
	}
